package com.xkstream.client.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.base.BaseActivity;
import com.xkstream.client.ui.kt.UploadLogFileActivity;
import com.xkstream.client.utils.DeviceUtils;
import com.xkstream.client.utils.LogFileUtil;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xiaoyi on 2017-9-26.
 * 帮助中心
 */

public class HelpActivity extends BaseActivity {
    @BindView(R.id.llCommonQuestion)
    LinearLayout llCommonQuestion;
    @BindView(R.id.llQuestionType)
    LinearLayout llQuestionType;

    @BindArray(R.array.common_question)
    String[] commonQuestions;

    @BindArray(R.array.help_url_common)
    String[] urls;

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_help);
        ButterKnife.bind(this);
        setTitle(R.string.help);
        addCommonQuestion();
        //addQuestionType();
    }

    @OnClick(R.id.headerBack)
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.headerBack:
                finish();
                break;
        }
    }


    private void addCommonQuestion() {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                , DeviceUtils.dp2px(this, 45));
        LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                , 1);
        for (String question : commonQuestions) {

        }

        for (int i = 0; i < commonQuestions.length; i++) {
            TextView tvQuestion = (TextView) View.inflate(this, R.layout.layout_question_item, null);
            tvQuestion.setText(commonQuestions[i]);
            llCommonQuestion.addView(tvQuestion, params);
            View divider = new View(this);
            divider.setBackgroundResource(R.color.header_divider);
            llCommonQuestion.addView(divider, dividerParams);
            int finalI = i;
            tvQuestion.setOnClickListener((v) -> {

                if (finalI == commonQuestions.length - 1) {
                    jumpToActivity(UploadLogFileActivity.class);
                }else {
                    Intent intent = new Intent(this,WebActivity.class);
                    intent.putExtra("url",urls[finalI]);
                    intent.putExtra("title",commonQuestions[finalI]);
                    jumpToActivity(intent);
                }
            });
        }

        llCommonQuestion.removeView(llCommonQuestion.getChildAt(llCommonQuestion.getChildCount() - 1));
    }

   /* private void addQuestionType() {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                , DeviceUtils.dp2px(this, 45));
        LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                , 1);
        for (String question : questionType) {
            TextView tvQuestion = (TextView) View.inflate(this, R.layout.layout_question_item, null);
            tvQuestion.setText(question);
            llQuestionType.addView(tvQuestion, params);
            View divider = new View(this);
            divider.setBackgroundResource(R.color.header_divider);
            llQuestionType.addView(divider, dividerParams);
            tvQuestion.setOnClickListener((v) -> {
                showTopTips(question);
            });
        }
        llQuestionType.removeView(llQuestionType.getChildAt(llQuestionType.getChildCount() - 1));
    }*/

}
